package com.yylending.las.personal.bandcard.verified;

import android.os.Parcel;
import android.os.Parcelable;

import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.infrastructure.network.entity.EmptyEntity;
import com.yylending.las.Global;

import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
 * M:实名认证
 * Created by ying_he on 2017/6/28.<br>
 * Copyright  2017 www.yylending.com. All Rights Reserved.<br><br>
 */

public class RealNameVerifiedModel extends Model {
    private static final String TAG = "RealNameVerifiedModel";

    @Override
    public Observable getObservable(Object params, int functionalCode) {
        Service service = (Service) NetworkHelper.createService(Service.class);
        return service.getRealNameVerify(Global.LOGIN_TOKEN, new EmptyEntity());
    }

    @Override
    public void onNext(Object entity) {
        RealNameVerifyResult result = cast(entity);
        EventAgent.post(result);
    }

    private interface Service {
        @POST("server/cuser/getAuth")
        Observable<RealNameVerifyResult> getRealNameVerify(@Header("token") String token, @Body EmptyEntity emptyEntity);
    }

    static class RealNameVerifyResult extends BaseResultEntity<RealNameVerify>{
    }

    static class RealNameVerify{
        public String auth;
        public String json;
    }

    static class DecryptJson {
        public RealNameInfo identity;
    }

    public static class RealNameInfo implements Parcelable{
        String inumber;
        public String iname;

        public RealNameInfo() {
        }

        protected RealNameInfo(Parcel in) {
            this.inumber = in.readString();
            this.iname = in.readString();
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {

        }

        public final static Creator<RealNameInfo> CREATOR = new Creator<RealNameInfo>() {
            @Override
            public RealNameInfo createFromParcel(Parcel source) {
                return new RealNameInfo(source);
            }

            @Override
            public RealNameInfo[] newArray(int size) {
                return new RealNameInfo[size];
            }
        };
    }
}
